<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>申请信息写</title>
    <link rel="stylesheet" href="https://www.layuicdn.com/layui/css/layui.css">
</head>
<body>
<form class="layui-form" action="" style="width: 70%">
    <div class="layui-form-item">
        <label class="layui-form-label">自习室编号</label>
        <div class="layui-input-block">
            <input type="hidden" name="studyRooms.studyroomId">
            <input type="text" id="studyroomId" name="studyRooms.studyroomId" disabled required lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">自习室楼号</label>
        <div class="layui-input-block">
            <input type="hidden" name="studyRooms.studyroomNumber">
            <input type="text" id="studyroomNumber" name="studyRooms.studyroomNumber" disabled required lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">学号</label>
        <div class="layui-input-inline">
            <input type="text" name="student.studentId" value="${sessionScope.student_user.studentId}" required lay-verify="required" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="student.studentName" value="${sessionScope.student_user.studentName}"  required lay-verify="required" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系方式</label>
        <div class="layui-input-inline">
            <input type="text" name="student.studentcontact" value="${sessionScope.student_user.studentcontact}" required lay-verify="required" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">学生学院</label>
        <div class="layui-input-inline">
            <input type="text" name="student.studentAcademy" value="${sessionScope.student_user.studentAcademy}" required lay-verify="required" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">使用时间</label>
        <div class="layui-inline" id="test6">
            <div class="layui-input-inline">
                <input type="text" autocomplete="off" name="startTime" id="test-startDate-1" class="layui-input" placeholder="开始日期">
            </div>
            <div class="layui-form-mid">-</div>
            <div class="layui-input-inline">
                <input type="text" autocomplete="off" name="closeTime" id="test-endDate-1" class="layui-input" placeholder="结束日期">
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">申请原因</label>
        <div class="layui-input-block">
            <textarea name="applyReason" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <a class="layui-btn"  id="save">立即提交</a>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script src="https://www.layuicdn.com/layui/layui.js"></script>
<script>
    layui.use(['form', 'layer', 'jquery','laydate'], function () {
        let form = layui.form;
        let layer = layui.layer;
        let $ = layui.jquery;
        let laydate = layui.laydate;

        laydate.render({
            elem: '#test6', //开始时间和结束时间所在 input 框的父选择器
            //设置开始日期、日期日期的 input 选择器
            range: ['#test-startDate-1', '#test-endDate-1'], //数组格式为 layui 2.6.6 开始新增
            type:'datetime'
        });

        $("#save").click(()=>{
            let serialize = $("form").serialize();
            $.post('/studyRoom/saveApplyRoom',serialize,response=>{
                // 提交申请
                if (response.code==='200'){
                    parent.layer.msg('申请成功', {icon: 1,time: 2000});
                }else {
                    parent.layer.msg(response.msg, {icon: 2});
                }
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            })
        });

        //TODO 需要做数据校验
        // $("input[name='student.studentId']").
        //
        // function rule() {
        //     let studentId = $("input[name='student.studentId']").val();
        //     let studentName = $("input[name='student.studentName']").val();
        //     let studentcontact = $("input[name='student.studentcontact']").val();
        //     let studentAcademy = $("input[name='student.studentAcademy']").val();
        //     let applyReason = $("textarea[name='student.applyReason']").val();
        //     if (){
        //
        //     }
        // }

    })
</script>
</body>
</html>